package com.huawei.hianalytics.ab.bc.ab;

import com.huawei.hianalytics.ab.bc.ef.ab;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;

public class gh implements fg {
    private PublicKey ab(byte[] bArr) {
        return KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(bArr));
    }

    private byte[] ab(byte[] bArr, PublicKey publicKey) {
        if (publicKey == null) {
            try {
                throw new UnsupportedEncodingException("The loaded public key is null");
            } catch (UnsupportedEncodingException e) {
                ab.cd("Rsa", "rsaEncrypt(): getBytes - Unsupported coding format!");
                return new byte[0];
            } catch (NoSuchAlgorithmException e2) {
                ab.cd("Rsa", "rsaEncrypt(): getInstance - No such algorithm,transformation");
                return new byte[0];
            } catch (InvalidKeyException e3) {
                ab.cd("Rsa", "rsaEncrypt(): init - Invalid key!");
                return new byte[0];
            } catch (NoSuchPaddingException e4) {
                ab.cd("Rsa", "rsaEncrypt():  No such filling parameters ");
                return new byte[0];
            } catch (BadPaddingException e5) {
                ab.cd("Rsa", "rsaEncrypt():False filling parameters!");
                return new byte[0];
            } catch (IllegalBlockSizeException e6) {
                ab.cd("Rsa", "rsaEncrypt(): doFinal - The provided block is not filled with");
                return new byte[0];
            }
        }
        Cipher instance = Cipher.getInstance("RSA/ECB/OAEPWITHSHA-1ANDMGF1PADDING");
        instance.init(1, publicKey);
        return instance.doFinal(bArr);
    }

    public String ab(String str, String str2) {
        ab.bc("Rsa", "No RSA decryption method");
        return "";
    }

    public String ab(String str, byte[] bArr) {
        if (bArr == null || bArr.length == 0) {
            ab.cd("Rsa", "encrypt: content is empty or null");
            return "";
        }
        try {
            return de.ab(ab(bArr, ab(de.ab(str))));
        } catch (NoSuchAlgorithmException e) {
            ab.cd("Rsa", "encrypt(): getInstance - No such algorithm,transformation");
            return "";
        } catch (InvalidKeySpecException e2) {
            ab.cd("Rsa", "encrypt(): Invalid key specification");
            return "";
        }
    }

    public String bc(String str, String str2) {
        try {
            return ab(str, str2.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            ab.bc("Rsa", "Unsupported encoding exception,utf-8");
            return "";
        }
    }
}
